﻿using System;
using System.Data;
using System.Text;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Garlic.CC.BaseClass;
using Garlic.CC.Utility;
using Garlic.BLL.Common;
using Garlic.DM.DataModel;
using Garlic.CC.WebUtility;
using Garlic.BLL;
using System.Collections.Generic;

public partial class SystemManagement_SystemConfigList : BasePage
{
    #region page load
    protected void Page_Load(object sender, EventArgs e)
    {

        try
        {
            if (!Page.IsPostBack)
            {
                //Init Page
            }
        }
        catch (Exception ex)
        {
            this.HandleException(ex);
        }
    }

    #endregion

    #region method

    /// <summary>
    /// 初始化查询栏
    /// </summary>
    private void InitSearchBar()
    {
        //初始化查询列表

        //List<PlantInfo> plants = plantMgr.GetListByUserID();
        //List<WorkshopInfo> workshops = workshopMgr.GetListByUserID();
        //List<SupplierInfo> suppliers = SupplierManager.GetListWithWorkshop();

        //this.PartSearchBar.ListSourcXYbles = ...
    }


    void InitPartActivity()
    {
    }

    void InitPartType()
    { }
       

    private void Search()
    {
        StringBuilder conditionBuilder = new StringBuilder();
        if (!string.IsNullOrEmpty(this.txtParameterName.Text.Trim()))
            conditionBuilder.AppendFormat("parameter_name = '{0}' AND ",SqlHelper.ReplaceInvalidWords( this.txtParameterName.Text.Trim()));
        if (!string.IsNullOrEmpty(this.txtParameterValue.Text.Trim()))
            conditionBuilder.AppendFormat("parameter_value = '{0}' AND ", SqlHelper.ReplaceInvalidWords(this.txtParameterValue.Text.Trim()));
        if (!string.IsNullOrEmpty(this.txtDefaultValue.Text.Trim()))
            conditionBuilder.AppendFormat("default_value = '{0}' AND ", SqlHelper.ReplaceInvalidWords(this.txtDefaultValue.Text.Trim()));
        if (this.ddChangeAble.Text.Trim() != "—")
            conditionBuilder.AppendFormat("changeable = {0} AND ", (this.ddChangeAble.Text.Trim() == "是") ? 1:0);

        string condition = conditionBuilder.ToString();
        if (!string.IsNullOrEmpty(condition))
        {
            if (condition.LastIndexOf(" AND ") != -1)
                condition = condition.Substring(0, condition.LastIndexOf(" AND "));
        }

        this.SmartDataViewSource.SelectParameters["textWhere"].DefaultValue = condition;

    }

    private void ShowMessage(string msg)
    {
        this.Message = msg;
    }

    #endregion

    #region toolbar event handler
    /// <summary>
    /// 工具栏事件处理
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="args"></param>
    protected void TopToolBar_OnClick(object sender, Garlic.UI.Components.IconButtonClickEventArgs args)
    {
            switch (args.Command)
            {
                case ToolbarCommand.Search:
                    Search();
                    break;
            }
        
    }
    #endregion 

    protected void SmartGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {

    }

    protected void SmartGrid_DataBound(object sender, EventArgs e)
    {
        foreach (GridViewRow row in this.SmartGrid.Rows)
        {
            //可修改的记录添加修改按钮
            if (SmartGrid.DataKeys[row.RowIndex]["changeable"].ToString() == "1")
            {
                row.Cells[0].Text = string.Format("<a href=\"javascript:openWindow('SystemConfigEdit.aspx?parameter_name={0}',580,230,'修改','yes');\">修改</a>", SmartGrid.DataKeys[row.RowIndex]["parameter_name"].ToString());
            }
        }
    }
}
